"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var str = "你好 ts！";
var blo = false;
// 数组
var arr1 = [1, 2, 3, 4];
var arr2 = [1, 2, 3, 4, "123", false];
// 泛型数组
var arrTest1 = [123];
var arrTest2 = [1, "2"];
// 元组
var arrTuple = ['str', 123, true];
// 怎么定义二维数组呢？
// 枚举类型
var Flag;
(function (Flag) {
    Flag[Flag["success"] = 1] = "success";
    Flag[Flag["error"] = 2] = "error";
})(Flag || (Flag = {}));
;
console.log(Flag.success);
// 枚举item无值时，会输出item对应index
var Color;
(function (Color) {
    Color[Color["red"] = 0] = "red";
    Color[Color["green"] = 1] = "green";
    Color[Color["yellow"] = 2] = "yellow";
})(Color || (Color = {}));
;
var b = Color.green;
console.log(b);
var Index;
(function (Index) {
    Index[Index["index1"] = 0] = "index1";
    Index["index2"] = "str";
    Index["index3"] = "1str";
})(Index || (Index = {}));
;
var index = Index.index1;
console.log(typeof index);
// let oNever:never;
// oNever = (()  => {
//   throw new Error('Error');
// })();
console.log('123');
// 函数定义
function fun(a, b, c) {
    if (c === void 0) { c = 12; }
    return a + b + c;
}
// alert(fun(1, 2, 4))
function funFor(a) {
    var results = [];
    for (var _i = 1; _i < arguments.length; _i++) {
        results[_i - 1] = arguments[_i];
    }
    var sum = 0;
    for (var i = 0; i < results.length; i++) {
        sum += results[i];
    }
    return sum;
}
// alert(funFor(1,2,3,4,5,6,7,8,9))
// ----------------
// ts定义类
var Person = /** @class */ (function () {
    function Person(n) {
        this.name = n;
    }
    // run():void{
    //   alert(this.name)
    // }
    Person.prototype.getName = function () {
        return this.name + "\u5728\u52A8\u6B21\u6253\u6B21";
    };
    Person.prototype.setName = function (name) {
        this.name = name;
    };
    return Person;
}());
var nP = new Person('张三');
// nP.run();
// alert(nP.getName());
nP.setName('毛利里斯');
// alert(nP.getName());
// ----------------
// ts中实现继承extends、super
var People = /** @class */ (function (_super) {
    __extends(People, _super);
    function People() {
        return _super !== null && _super.apply(this, arguments) || this;
    }
    return People;
}(Person));
var Sonobj = new People('士大夫');
// alert(Sonobj.getName());
var SonBrother = /** @class */ (function (_super) {
    __extends(SonBrother, _super);
    function SonBrother(name) {
        return _super.call(this, name) || this;
    }
    SonBrother.prototype.run = function () {
        return this.name + "\u5728biubiubiu";
    };
    return SonBrother;
}(Person));
var SB = new SonBrother('铝合金');
// alert(SB.getName());
// alert(SB.run());
// ----------------
// 类修饰符 typescript中提供了三种修饰符（默认public）
/*
  public      公有        在类里面、子类、类外均可访问
  protected   保护类型    在类里面、子类可访问，类外不可访问
  private     私有        类里可访问，子类、类外不可访问
*/
var Parent = /** @class */ (function () {
    function Parent(n) {
        this.name = n;
    }
    return Parent;
}());
var Son = /** @class */ (function (_super) {
    __extends(Son, _super);
    function Son(name) {
        return _super.call(this, name) || this;
    }
    Son.prototype.work = function () {
        return this.name;
    };
    return Son;
}(Parent));
var son = new Parent('我是pulic');
// alert(son.name)
// ----------------
// 静态属性、静态方法
var staticObj = /** @class */ (function () {
    function staticObj(type) {
        this.typeTest = type;
    }
    staticObj.print = function () {
        // alert('print方法'+this.typeName)
    };
    staticObj.typeName = "静态数据";
    return staticObj;
}());
staticObj.print();
// alert(staticObj.typeName)
// ----------------
// 多态
var Animal = /** @class */ (function () {
    function Animal(name) {
        this.name = name;
    }
    Animal.prototype.eat = function () {
        console.log("吃东西");
    };
    return Animal;
}());
var Dog = /** @class */ (function (_super) {
    __extends(Dog, _super);
    function Dog(name) {
        return _super.call(this, name) || this;
    }
    Dog.prototype.eat = function () {
        return this.name + '吃骨头';
    };
    return Dog;
}(Animal));
var Cat = /** @class */ (function (_super) {
    __extends(Cat, _super);
    function Cat(name) {
        return _super.call(this, name) || this;
    }
    Cat.prototype.eat = function () {
        return this.name + '吃鱼';
    };
    return Cat;
}(Animal));
// ----------------
// 抽象类，是提供其子类所继承的基类，不能直接实例化，并且其子类必须定义此抽象类
// abstract抽象类，标准：Animal这个类的子类必须包含eat方法，即抽象类和抽象方法用来定义标准
var absAnimal = /** @class */ (function () {
    function absAnimal(name) {
        this.name = name;
    }
    return absAnimal;
}());
// 父类中定义抽象类方法eat，子类必须具有此方法
var absDog = /** @class */ (function (_super) {
    __extends(absDog, _super);
    function absDog(name) {
        return _super.call(this, name) || this;
    }
    absDog.prototype.eat = function () {
        console.log(this.name + "吃骨头");
    };
    return absDog;
}(absAnimal));
var AD = new absDog("黑子");
AD.eat();
var absCat = /** @class */ (function (_super) {
    __extends(absCat, _super);
    function absCat(name) {
        return _super.call(this, name) || this;
    }
    absCat.prototype.eat = function () {
        console.log(this.name + "吃鱼");
    };
    return absCat;
}(absAnimal));
var AC = new absCat("咪咪");
AC.eat();
// ----------------
// 接口
// json约束
function constraintJson(labelInfo) {
    alert(labelInfo.label);
}
function printName(name) {
    // alert(name.firstNamt + "---" + name.lastName)
}
var oObj = {
    firstNamt: "李",
    lastName: "四",
    age: 20,
    sex: "男"
};
printName(oObj);
function ajax(config) {
    var xhr = new XMLHttpRequest();
    xhr.open(config.type, config.url, true);
    xhr.send(config.data);
    xhr.onreadystatechange = function () {
        if (xhr.readyState === 4 && xhr.status === 200) {
            console.log("change");
            if (config.dataType === "json") {
                console.log("JSON：", JSON.parse(xhr.responseText));
            }
            else {
                console.log(xhr.responseText);
            }
        }
    };
}
ajax({
    type: "get",
    url: "http://a.itying.com/api/productlist",
    data: "name=zhangsan",
    dataType: "json"
});
var arr = { name: "在jam萨满" };
var Pig = /** @class */ (function () {
    function Pig(name) {
        this.name = name;
    }
    Pig.prototype.eat = function () {
        console.log(this.name + "吃🐖食");
    };
    return Pig;
}());
var d = new Pig("猪猪侠");
d.eat();
var Programmer = /** @class */ (function () {
    function Programmer(name) {
        this.name = name;
    }
    Programmer.prototype.codding = function (code) {
        console.log(this.name + code);
    };
    return Programmer;
}());
// 继承类并且实现接口
var dWeb = /** @class */ (function (_super) {
    __extends(dWeb, _super);
    // public name:string;
    function dWeb(name) {
        // this.name = name;
        return _super.call(this, name) || this;
    }
    dWeb.prototype.eat = function () {
        console.log(this.name + "吃大骨头~！");
    };
    dWeb.prototype.work = function () {
        console.log(this.name + "汪汪汪~！");
    };
    return dWeb;
}(Programmer));
var DDog = new dWeb("大黄");
DDog.eat();
DDog.work();
DDog.codding("写ts汪汪汪~！");
// ----------------
// 泛型
var getData = function (value) {
    return value;
};
getData("123");
getData(123);
getData(true);
// 泛型类
var MinClass = /** @class */ (function () {
    function MinClass() {
        this.list = [];
    }
    MinClass.prototype.add = function (num) {
        this.list.push(num);
    };
    MinClass.prototype.min = function () {
        var minNum = this.list[0];
        for (var i = 0; i < this.list.length; i++) {
            if (minNum > this.list[i]) {
                minNum = this.list[i];
            }
        }
        return minNum;
    };
    return MinClass;
}());
var testMin = new MinClass;
testMin.add(12);
testMin.add(1);
testMin.add(22);
alert("最小值：" + testMin.min());
// 升级版
var MinClassOptimize = /** @class */ (function () {
    function MinClassOptimize() {
        this.list = [];
    }
    MinClassOptimize.prototype.add = function (value) {
        this.list.push(value);
    };
    MinClassOptimize.prototype.min = function () {
        var minNum = this.list[0];
        for (var i = 0; i < this.list.length; i++) {
            if (minNum > this.list[i]) {
                minNum = this.list[i];
            }
        }
        return minNum;
    };
    return MinClassOptimize;
}());
// number则比较大小，string则比较ASCII码
var MinValue = new MinClassOptimize();
MinValue.add('c');
MinValue.add('z');
MinValue.add('a');
alert(MinValue.min());
var getIntfData = function (value) {
    return value;
};
getIntfData('张三很烦');
getIntfData(666);
// 类作为参数约束数据传入的类型
var User = /** @class */ (function () {
    function User() {
    }
    return User;
}());
var MysqlDb = /** @class */ (function () {
    function MysqlDb() {
    }
    MysqlDb.prototype.add = function (user) {
        console.log(user);
        return true;
    };
    return MysqlDb;
}());
var uu = new User();
uu.userName = "周日";
uu.password = "123456";
var Db = new MysqlDb();
Db.add(uu);
// 操作数据库的泛型类
var MysqlIntf = /** @class */ (function () {
    function MysqlIntf() {
    }
    MysqlIntf.prototype.add = function (info) {
        console.log(info);
        return true;
    };
    MysqlIntf.prototype.updata = function (info, id) {
        console.log(info, id);
        return true;
    };
    return MysqlIntf;
}());
var AticalInfo = /** @class */ (function () {
    function AticalInfo(params) {
        this.title = params.title;
        this.desc = params.desc;
        this.status = params.status;
    }
    return AticalInfo;
}());
var aa = new AticalInfo({
    title: "周日",
    desc: "学习ts",
});
// aa.title = "周日";
// aa.desc = "学习ts";
// aa.status = 1;
var AAMys = new MysqlIntf();
AAMys.add(aa);
AAMys.updata(aa, 13);
// ----------------
// 定义一个操作数据库的库 支持Mysql Mssql MongoDb
var db_1 = require("./modules/db");
var user_1 = require("./model/user");
// 定义类和数据库做映射
// class UserClass{
//   userName:string | undefined;
//   password:string | undefined;
// }
var uuu = new user_1.UserClass();
uuu.userName = "1111";
uuu.password = "1234566666";
// let oooMysql = new MysqlDbClass<UserClass>();
// 模块化引入后直接使用
var oooMysql = user_1.UserModel;
oooMysql.add(uuu);
console.log("获取data：", oooMysql.get(1));
var oooMyssql = new db_1.MyssqlDbClass();
oooMyssql.add(uuu);
// ----------------
// 模块祥见./modules
